import React, { PureComponent } from 'react';
import { Card, Tabs, Select, Button } from 'antd';
import { PageHeaderWrapper } from '@ant-design/pro-layout';

import _ from 'lodash';
import router from 'umi/router';

import { connect } from 'dva';
import ProjectsPath from '@/components/ProjectsPath';
import CurrentStage from '../components/CurrentStage';

@connect(state => ({
  orgStructure: state.orgStructure,
  currentUser: state.user.currentUser.data,
}))
export default class ChoseOrg extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {
    const { dispatch } = this.props;
  }

  handleStandardFiltrateChange() {
    const { showFiltrate } = this.state;
    this.setState({
      showFiltrate: !showFiltrate,
    });
  }

  render() {
    const { orgStructure } = this.props;
    const alias =
      this.props.currentUser && this.props.currentUser.alias ? this.props.currentUser.alias : '';

    const localStorageProjects = localStorage.getItem('projects');
    let projects = {};
    if (_.has(JSON.parse(localStorageProjects), alias)) {
      projects = JSON.parse(localStorageProjects)[alias];
    }

    if (!_.isEmpty(orgStructure.data)) {
      // 筛选到第一个项目
      let project = '';
      let level1Id = '';
      let level2Id = '';
      let orgnofullpath = '';
      let projectId = '';
      if (
        !_.isEmpty(projects) &&
        _.filter(orgStructure.data, { orgdepid: projects.project }).length
      ) {
        const params = projects;
        projectId = params.project;
        level1Id = params.level1;
        level2Id = params.level2;
      } else {
        project = _.filter(orgStructure.data, { hrOrgTypeId: '31' });
        orgnofullpath = project[0].orgnofullpath.split('-');
        level1Id = orgnofullpath[orgnofullpath.length - 4];
        level2Id = orgnofullpath[orgnofullpath.length - 3];
        projectId = project[0].orgdepid;
      }
      // 跳转第一个项目的全盘货值
      router.replace(
        `/OperatingPlan/SupplyPlan/EntireProject/${level1Id}/${level2Id}/${projectId}`,
      );
    }
    return false;
    // return (
    //   <PageHeaderWrapper
    //     breadcrumb={null}
    //     title={<ProjectsPath {...this.props} editing />}
    //     tags={<CurrentStage {...this.props} />}
    //     extra={[]}
    //   >
    //     <Card></Card>
    //   </PageHeaderWrapper>
    // );
  }
}
